package io.geekidea.springbootplus.system.controller;

import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.system.entity.SysBrowse;
import io.geekidea.springbootplus.system.entity.SysPermission;
import io.geekidea.springbootplus.system.service.SysBrowseService;
import io.geekidea.springbootplus.system.vo.SysBrowseQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Controller
@RequestMapping("/sysBrowse")
@Module("system")
@Api(value = "商品浏览api", tags = {"商品浏览"})
public class SysBrowseController {
    @Autowired
    private SysBrowseService sysBrowseService;

    @GetMapping("/getSysCommentList/{productId}")
    @RequiresPermissions("sys:permission:all:menu:list")
    @OperationLog(name = "获取商品浏览信息", type = OperationLogType.LIST)
    @ApiOperation(value = "获取商品浏览信息", response = SysPermission.class)
    public ApiResult<List<SysBrowseQueryVo>> getSysBrowseList(@PathVariable("productId") Integer productId) {
        List<SysBrowseQueryVo> list = sysBrowseService.getSysBrowseList(productId);
        return ApiResult.ok(list);
    }

    @PostMapping("/addSysBrowse")
    @OperationLog(name = "写入浏览信息", type = OperationLogType.ADD)
    @ApiOperation(value = "写入浏览信息", response = ApiResult.class)
public ApiResult<Boolean> addSysBrowse(@Validated(Add.class) @RequestBody SysBrowse sysBrowse) throws Exception {

        boolean flag = sysBrowseService.saveSysBrowse(sysBrowse);
        return ApiResult.result(flag);
    }
}
